package com.sysofstudent.web.admin;


import com.sysofstudent.po.Score;
import com.sysofstudent.po.Student;
import com.sysofstudent.service.StudentService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class AdminController {

    @Resource
    StudentService studentService;


    @RequestMapping("/admin/StudentInfo")
    public String StudentInfo(Model model)
    {
        List<Student> students=studentService.getStudentList();
        model.addAttribute("students",students);
        System.out.println(" here is student info");
        return "/admin/StudentInfo";
    }

    @RequestMapping("/admin/StudentInfo/ShowInfo{number}")
    public String ShowInfo(Model model,@PathVariable String number)
    {
        Student student=studentService.findStudent(number);
        model.addAttribute("student",student);
        return "/admin/ShowInfo";
    }

    @RequestMapping("/admin/StudentInfo/toEdit{number}")
    public String toEdit(Model model,@PathVariable String number)
    {
        Student student=studentService.findStudent(number);
        model.addAttribute("student",student);
        return "/admin/toEdit";
    }

    @RequestMapping("/admin/StudentInfo/edit")
    public String edit(Student student)
    {
        studentService.edit(student);
        return "redirect:/admin/StudentInfo";
    }

    @RequestMapping("/admin/StudentInfo/delete{id}")
    public String delete(Model model,@PathVariable Long id)
    {
        studentService.delete(id);
        return "redirect:/admin/StudentInfo";
    }

    @RequestMapping("/admin/StudentInfo/toAdd")
    public String toAdd(Model model)
    {
        Student student=new Student();
        model.addAttribute("student",student);
        return "admin/toAdd";
    }

    @RequestMapping("/admin/StudentInfo/add")
    public String add(Student student)
    {
        studentService.save(student);
        return "redirect:/admin/StudentInfo";
    }


}
